//
//  SectionHeaderDetailVC.m
//  VTravel
//
//  Created by lanouhn on 16/8/3.
//  Copyright © 2016年 xiaoYu. All rights reserved.
//

#import "SectionHeaderDetailVC.h"
#import "RootScrollViewModel.h"
#import "PickDestinationTableViewCell.h"

#import "NearByCellClickDetailVC.h"

@interface SectionHeaderDetailVC ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
/** 数据源数组 */
@property (nonatomic, strong) NSMutableArray *dataArray;

@end

@implementation SectionHeaderDetailVC
/** 懒加载 */
- (NSMutableArray *)dataArray{
    if (_dataArray == nil) {
        self.dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

/** 精选旅游目的地更多数据解析 */
- (void)requestData{
    [NetWorkManager requestForGETWithURL:kPickDesMoreDetailURL paramater:@{@"city_id":city_id,@"adType":@"119"} success:^(id responseObject) {
        
        NSArray *array = responseObject[@"data"];
        for (NSDictionary *dic in array) {
            RootScrollViewModel *model = [[RootScrollViewModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            model.src = ImageURL(dic[@"src"]);
            [self.dataArray addObject:model];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.tableView reloadData];
        });
        
    } fail:^(NSError *error) {
        
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = kRandomColor;
    
    [self requestData];
    
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerNib:[UINib nibWithNibName:@"PickDestinationTableViewCell" bundle:nil] forCellReuseIdentifier:@"PickDestinationTableViewCell"];
    
    [self.view addSubview:self.tableView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    PickDestinationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PickDestinationTableViewCell" forIndexPath:indexPath];
    if (self.dataArray != nil) {
        cell.model = self.dataArray[indexPath.row];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 130;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    PickDestinationTableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    kMyLog(@"%@", cell.nameLabel.text);
    NearByCellClickDetailVC *detailVC = [[NearByCellClickDetailVC alloc] init];
    detailVC.hidesBottomBarWhenPushed = YES;
    detailVC.TitleStr = cell.nameLabel.text;
    detailVC.type = XYPushTransitionTypeFromRootPickerDestinationCells;
    [self.navigationController pushViewController:detailVC animated:YES];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
